<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<style>
		body{
			margin: 0;
			padding: 0;
		}
		.box{
			/* background-color: #3333; */
			height: 150px;
			width: 150px;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 20px;
      font-size: 12px;
		}
		.loading span{
			display: inline-block;
			width: 15px;
			height: 100%;
			margin-right: 5px;
			background: #f30;
			-webkit-transform-origin: right bottom;
			-webkit-animation: load 1s ease infinite;
		}
		.loading span:last-child{
			margin-right: 0px; 
		}
		@-webkit-keyframes load{
			0%{
				opacity: 1;
				-webkit-transform: scale(1);
			}
			100%{
				opacity: 0;
				-webkit-transform: rotate(90deg) scale(.3);
			}
		}
		.loading span:nth-child(1){
			-webkit-animation-delay:0.13s;
		}
		.loading span:nth-child(2){
			-webkit-animation-delay:0.26s;
		}
		.loading span:nth-child(3){
			-webkit-animation-delay:0.39s;
		}
		.loading span:nth-child(4){
			-webkit-animation-delay:0.52s;
		}
		.loading span:nth-child(5){
			-webkit-animation-delay:0.65s;
		}
	</style>
	<body>
		<div class="box">
			<div class="loading" style=" height: 15px; width: 120px; ">
				<span></span>
				<span></span>
				<span></span>
				<span></span>
				<span></span>
			</div>
		</div>
	</body>
	<script>
    // document.getElementsByClassName('box')[0].innerHTML = navigator.userAgent
		const BASE_URL = '//web-test.gamersky.com/GameUnionOperationPlatform/'
    const WE_KEY = 'gamersky_mobile_sdk'
		const TOKEN = {
				sessionToken: sdk.getSessionToken(),
				userOpenId: sdk.getUserOpenId()
			}
		const PAY_DATA = JSON.parse(sdk.payOrderJson())
		
    // WE_POST('/',{},'post')
		function WE_POST (url,data,methods) {
			return new Promise((resolve, reject) => {
				const xhr = new XMLHttpRequest();
				xhr.onreadystatechange = function () {
					if (xhr.readyState === 4) // 请求完成
						if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304){
							const res = JSON.parse(xhr.responseText)
							res.info = res.errorDescription
							const { error,info } = res
							if(error != '' ){
								sdk.finish('')
								reject(info || error)
							}
							delete res.error
							delete res.errorDescription
							resolve(res)
						}else
							reject(xhr.status)
				}
				xhr.open(methods || 'post', BASE_URL + url, true)
				xhr.setRequestHeader('content-type', 'application/json')
				xhr.send(JSON.stringify({
					...data,
					...TOKEN
				}))
			})
		}
		
		const timesleep = sleep => new Promise( ok=>{ setTimeout(()=>{ ok() },sleep) } )
		
		window.onload = async () => {
      if(navigator.userAgent.includes(WE_KEY)){
        const { price,payMethod } = PAY_DATA
        const [reason,side,sidedevice] = [`购买游米${PAY_DATA.youMiOrderPrice}元`,'wap','Android']
        const { serialNumber } = await WE_POST('YouMiOrders/CreateYouMiOrder',{ reason,sidedevice,side,...PAY_DATA })
        const { payURL } = await WE_POST('YouMiOrders/PayYouMiOrder',{serialNumber})
        await timesleep(800)
        window.open(payURL)
        sdk.finish(serialNumber)
      }
		}
	</script>
</html>